package com.alibaba.citrus.ots.application.report.ability.repository.impl;

import com.alibaba.citrus.ots.application.report.ability.repository.MonthSalesCompanyCategoryReportWriteRepository;
import com.epoch.app.otsapplicationreportsdk.model.dto.MonthSalesBasicReportSDO;
import com.epoch.app.otsapplicationreportsdk.monthsalescompanycategoryreport.dto.UpdateResponse;
import com.epoch.app.otsapplicationreportsdk.monthsalescompanycategoryreport.model.MonthSalesCompanyCategoryReport;
import com.epoch.app.otsapplicationreportsdk.monthsalescompanycategoryreport.service.MonthSalesCompanyCategoryReportService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author zhoubc
 * @description: TODO
 * @date 2021/12/10 23:06
 */
@Component
public class MonthSalesCompanyCategoryReportWriteRepositoryImpl implements MonthSalesCompanyCategoryReportWriteRepository {

    @Resource
    MonthSalesCompanyCategoryReportService monthSalesCompanyCategoryReportService;

    @Override
    public String add(MonthSalesBasicReportSDO sdo) {
        MonthSalesCompanyCategoryReport monthSalesCompanyCategoryReport = new MonthSalesCompanyCategoryReport();
        BeanUtils.copyProperties(sdo,monthSalesCompanyCategoryReport);
        Map m = (Map)monthSalesCompanyCategoryReportService.create(monthSalesCompanyCategoryReport);
        Map result = (Map)m.get("result");
        return (String)result.get("lastInsertId");
    }

    @Override
    public Integer update(MonthSalesBasicReportSDO sdo) {
        MonthSalesCompanyCategoryReport monthSalesCompanyCategoryReport = new MonthSalesCompanyCategoryReport();
        BeanUtils.copyProperties(sdo,monthSalesCompanyCategoryReport);
        UpdateResponse response = monthSalesCompanyCategoryReportService.update(monthSalesCompanyCategoryReport);
        return response.getCount();
    }


}
